import { createRouter, createWebHashHistory } from 'vue-router';
import permission from './permission';
const constRoutes = [
  {
    path: '/replace',
    meta: { title: 'replace' },
    name: 'replace',
    component: () => import('@/views/replace.vue'),
  },
  {
    path: '/:pathMatch(.*)*',
    meta: { title: '404' },
    name: '404',
    component: () => import('@/views/404.vue'),
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes: [...constRoutes],
})

// 全局路由守卫
permission(router);

// 重置路由
export function resetRouter() {
  router.getRoutes().forEach((route: any) => {
    const { name } = route
    if (name) router.removeRoute(name)
  })
  constRoutes.forEach(v => { router.addRoute(v) })
}

export default router
